package easytasks.ui;

import easytasks.logic.TaskNotificationManager;
import easytasks.main.R;
import easytasks.settings.Settings;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

public class SettingsActivity extends PreferenceActivity
{	
	private OnSharedPreferenceChangeListener listener;
	
	@Override
    protected void onCreate(Bundle savedInstanceState) 
	{
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
        
        listener = new OnSharedPreferenceChangeListener() {			
			public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
			{
				if (key != null && key.equals(Settings.ENABLE_NOTIFICATIONS_KEY))
				{
					new TaskNotificationManager(SettingsActivity.this).updateNotificationAlarm();
				}
			}
		};
		
		PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(listener);
    }
}
